package com.situ.view;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class MainView {

    public static void main(String[] args) throws FileNotFoundException, IOException {
        ParkingViews pViews = null;

        try {
            ObjectInputStream ois = new ObjectInputStream(new FileInputStream("Object.dat"));
            pViews = (ParkingViews) ois.readObject();
            ois.close();
        } catch (ClassNotFoundException e) {
            System.out.println("文件不匹配");
        } catch (IOException e) {
            e.printStackTrace();
        }
        if(pViews == null) {
            pViews = new ParkingViews();
        }

        char key = '0';
        boolean flag = true;
        while (flag) {
            key = pViews.menu();
            switch (key) {
            case '1':
                // 存在默认车辆，停车记录
                pViews.listRecords();
                break;
            case '2':
                // 停车位状态
                pViews.listSpots();
                break;
            case '3':
                // 停车
                pViews.insertCar();
                break;
            case '4':
                // 取车
                pViews.getCar();
                break;
            case '0':
                flag = false;
                break;
            default:
                break;
            }
        }

        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("Object.dat"));
        oos.writeObject(pViews);
        oos.flush();
        oos.close();
    }

}
